﻿using System.IO;
using NUnit.Framework;
using StoryQ;
using TripleA.StoryQ;

namespace TripleA.Tests.FileSystem
{
    [TestFixture]
    public class FileSystemTests : BddFeature
    {
        protected override Feature DescribeFeature()
        {
            return new Story("Testing the file system extensions")
                .InOrderTo("Interact with the file system")
                .AsA("system test")
                .IWant("triplea extensions to handle this for me");
        }

        [Test]
        public void CleanFolderTest()
        {
            using (var domain = new FileSystemDomain())
            {
                const string source = @"FileSystem\TestData";
                var target = Path.Combine(source, Path.GetRandomFileName());

                Feature.WithScenario("Ensure that the contents of a non-empty filepath are cleaned")
                    .Given(domain.TheCloneFolderStepIsUsed, source, target)
                    .When(domain.TheCleanFolderStepIsUsed, target)
                    .Then(domain.TheFolderIsEmptyStepIsUsed, target)
                    .ExecuteWithReport();
            }
        }

        [Test]
        public void FileExistsTest()
        {
            using (var domain = new FileSystemDomain())
            {
                const string source = @"FileSystem\TestData";

                Feature.WithScenario("Ensure that the filepath contains a file test works")
                    .Given(domain.TheFolder_ShouldContainFile_, source, "somefile1.txt")
                    .ExecuteWithReport();
            }
        }

        [Test]
        public void WildcardFileExistsTest()
        {
            using (var domain = new FileSystemDomain())
            {
                const string source = @"FileSystem\TestData";

                Feature.WithScenario("Ensure that the filepath contains a file specified with a wildcard")
                    .Given(domain.TheFolder_ShouldContainFile_, source, "somefile*.txt")
                    .ExecuteWithReport();
            }
        }

        [Test]
        public void WildcardFileNotExistsTest()
        {
            using (var domain = new FileSystemDomain())
            {
                const string source = @"FileSystem\TestData";

                Feature.WithScenario("Ensure that the filepath does not contain files specified with a wildcard")
                    .Given(domain.TheFolder_ShouldNotContainFile_, source, "james*.txt")
                    .ExecuteWithReport();
            }
        }
    }
}